<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> 
    <title>注册</title>
    <link rel="stylesheet" href="<%=basePath%>static/css/sharestyle.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/sharestyle_active.css">
       <script src="<%=basePath%>static/js/jquery-3.2.1.min.js"></script>
    <script src="<%=basePath%>static/js/sharetextjs_active.js"></script>
    <style>

    /*img{width:100%;height:100%;}*/

</style>
</head>
<body bgcolor="#7062ee">
    <div class="register-bg">
        <div class="register-close">
           <!--  <img src="static/picture/x.png"> -->
        </div>
        <div class="register-detail">
           
            <div class="register-banner" style="background:url(${sharepic});background-size: 9.6rem 13.6rem;">
                <c:if test="${userid == null }"><div style="text-align:center">未查询到分享者，请联系客服</div></c:if>
                <c:if test="${userid != null }">
                <form>
                    <div class="inputdiv" style="display: none">
                        <input type="text" class="phone" id="parentid" name="parentid" value="${parentid}"  >
                        <input type="text" class="phone" id="userid" name="userid" value="${userid}" style="display: none">
                    </div>
                    <div class="inputdiv">
                        <img src="<%=basePath%>static/picture/zc.png">
                        <input type="text" class="phone" id="name" name="name" placeholder="请输入昵称">
                    </div>
                    <div class="inputdiv">
                        <img src="<%=basePath%>static/picture/phone12.png">
                        <input type="text" class="phone" id="username" name="username" placeholder="请输入注册手机号码">
                    </div>
                    <div class="inputdiv">
                        <img src="<%=basePath%>static/picture/yz.png">
                        <input class="register-code code"  style="margin-right:0" id="tel_check" name="tel_check" type="text"  placeholder="请输入注册验证码">
                        <button id="btn" class="cxfsyz">获取验证码</button>
                    </div>
                </form>
                </c:if>
            </div>
            <div class="register-btn registerbtn">
                <c:if test="${parentid == '68403bea3cae46d9b05650011ce9cab1'}"><p style="display:flex;flex-direction: row;font-size: .36rem;align-items: center;justify-content: center;color:#8f8f8f;margin-top:3px;"><input type="radio" name="vehicle" value="Car" checked="checked" style="border-radius:50%;">已确认下载并同意<a href="http://smms.sbdznkj.com:2018/file/AboutUs/xinguanjia/about.html" style="color:#4996f3">相关条款</a></p></c:if>
                <c:if test="${parentid != '68403bea3cae46d9b05650011ce9cab1'}"><p style="display:flex;flex-direction: row;font-size: .36rem;align-items: center;justify-content: center;color:#8f8f8f;margin-top:3px;"><input type="radio" name="vehicle" value="Car" checked="checked" style="border-radius:50%;">已确认下载并同意<a href="http://smms.sbdznkj.com:2018/file/AboutUs/about.html" style="color:#4996f3">相关条款</a></p></c:if>
                <a class="register_btn" href="javascript:void(0)">
                    <img src="<%=basePath%>static/picture/rbtn.png">
                    <span>注册</span>
                </a>
            </div>
            
        </div>
        
    </div>
    <script type="text/javascript" src="<%=basePath%>static/js/shareshowwapdialog.js"></script>
    <script type="text/javascript">
       /* var countdown=60; 
        function sendemail(){
            var obj = $("#btn");
            settime(obj);
            
            }
        function settime(obj) { //发送验证码倒计时
            if (countdown == 0) { 
                obj.attr('disabled',false); 
                //obj.removeattr("disabled"); 
                obj.html("获取验证码");
                countdown = 60; 
                return;
            } else { 
                obj.attr('disabled',true);
                obj.html("重新发送(" + countdown + ")");
                countdown--; 
            } 
        setTimeout(function() { 
            settime(obj) }
            ,1000) 
        }*/
    </script>
    
    <script>
    $(function () {
        register.init();
    });
    var register = {
        nchash: 'e7a37603',
        share: 1,
        quickStore: 0,
        init: function () {
//            register.verification();
            $('.cxfsyz').on('click', function () {
                register.getCode();
                return false;
            });
            $('#tel_check').blur(function () {
                register.telCheck();
                return false;
            });
            $('.register_btn').on('click', function () {
                register.nowSubmit();
                return false;
            });
            $('.register_txt2').on('click', function () {
                register.login();
                return false;
            })
//            $('.verification').on('click', function () {
//                register.reVerification();
//                return false;
//            });
        },
        verification: function () {
            $('.verification img').attr('src', "http://app.huitongtel.com/shop/index.php?act=seccode&op=makecode&nchash=" + register.nchash);
        },
        reVerification: function () {
            $('.verification img').attr('src', "http://app.huitongtel.com/shop/index.php?act=seccode&op=makecode&nchash=" + register.nchash + "&t=" + Math.random())
        },
        checkVerf: function () {
            register.sendCode();
            return false;
        },
        getCode: function () {
            register.checkVerf();
        },
        setRemainTime: function (curCount) {
            if (curCount == 0) {
                $('#btn').attr("disabled", false);
                $('.cxfsyz').css("color", "rgb(253,34,28)");
                $(".cxfsyz").text("重新发送");
                register.reVerification();
            } else {
            	$('#btn').attr("disabled", true);
                $('.cxfsyz').css("color", "#7B7B7B");
                $(".cxfsyz").text(curCount + 's');
                curCount--;
                setTimeout(function () {
                    register.setRemainTime(curCount)
                }, 1000)
            }
        },
        sendCode: function () {
            var tel = $('#username').val();
            var parentid = $('#parentid').val();
            if (tel == null || $.trim(tel) == '') {
                showWapMesError('请输入您的手机号码');
                return false;
            }

            var partten = /^(((13[0-9]{1})|(14[579]{1})|(15[^4,\D]{1})|(16[6]{1})|(18[0-9]{1})|(17[^249,\D]{1})|(19[89]{1}))+\d{8})$/;
            if (!partten.test(tel)) {
                showWapMesError('请输入正确的手机号码');
                return false;
            }
            $.ajax({
                type: 'POST',
                url: '../login/smsInfo',
                data: {
                	Mobile: tel,
                    ParentId: parentid,
                },
                dataType: 'json',
                success: function (data) {
                	if (data.errorCode != 2000) {
                    	// 发送失败
                        alert(data.data);
                    } else {
	                    alert('验证码发送成功');
	                    var curCount = 60;
	                    register.setRemainTime(curCount);
	                    
                    }
                }
            });
        },
        nowSubmit: function () {
            // 注册隐藏
            $('.register_btn').css("visibility","hidden");
            var username = $('#username').val();
            var name = $('#name').val();
            var tel_check = $('#tel_check').val();
            var parentid = $('#parentid').val();
            var userid = $('#userid').val();

            if (tel_check.length == 0) {
                showWapMesError('请输入短信验证码');
                $('.register_btn').css("visibility","visible");
                return false;
            }
            if (username.length == 0) {
                showWapMesError('手机号不允许为空');
                $('.register_btn').css("visibility","visible");
                return false;
            }
            if (name.length == 0) {
                showWapMesError('姓名不允许为空');
                $('.register_btn').css("visibility","visible");
                return false;
            }
            
            var flag = false;
            $.ajax({
                type: 'POST',
                url: '../login/boofalg',
                data: {
                	tel_check: tel_check,
                	Mobile: username,
                	ParentID: parentid
                },
                async: false,
                success: function (data) {
                	 if (data == 1) {
                         alert('验证码错误请重新输入');
                         flag = true;
                     }
                }
            });
            // 验证码错误 则执行false 否则不执行这段
            if(flag){
                $('.register_btn').css("visibility","visible");
                return false;
            }
            // 开始注册
            $.ajax({
                type: 'POST',
                url: '../login/shareRegister',
                data: {
                	Mobile: username,
                    UserName: name,
                    ShareId: userid
                },
                success: function (data) {
                    console.log(data);
                    if (data.errorCode != 2000) {
                        // 注册失败
                        alert(data.data);
                        location.href = "../login/shareDownload?userid="+ userid;
                        // 失败显示
                        $('.register_btn').css("visibility","visible");
                    } else {
                    	// 注册成功
                        var parentid = $('#parentid').val();
                    	alert("您默认的登陆密码为手机号码，感谢您的注册！");
                    	if(parentid != 'f917c37ae16c406ca9fc731a103af302'){
                            location.href = "../login/shareDownload?userid="+ userid;
                        }else{
                            location.href = "http://smms.sbdznkj.com:2018/SbdVoip/LiteWxhtml/PhoneCall.html";
                        }
                    }
                },
                dataType: 'json'
            });
        },
        login: function () {
        	// location.href = "index.php?act=login";
        }
    };
    
    //alert弹窗去掉上方网址标题
    window.alert = function (name) {
  	  const iframe = document.createElement('IFRAME');
  	  iframe.style.display = 'none';
  	  iframe.setAttribute('src', 'data:text/plain,');
  	  document.documentElement.appendChild(iframe);
  	  window.frames[0].window.alert(name);
  	  iframe.parentNode.removeChild(iframe);
    };


</script>
</body>
</html>
